<template>
	<view class="opinion">
		<view class="textarea">
			<textarea v-model="text" placeholder="请输入您要反馈的问题" maxlength="300"/>
		</view>
		<view class="opinion_img">
			<view class="t_title">
				请提供问题的截图或者照片(选填)
			</view>
			<view class="t_list">
				<view class="list" v-for="(v,i) in imgs" :key="i" :data-i="i" @click="changeImg">
					<image v-if="v" :src="http+v" mode=""></image>
				</view>
				<view class="list" @click="addImg">
					<image src="../../static/mine/tianjia.png" mode=""></image>
				</view>
			</view>
		</view>
		<view class="opinion_p">
			<view class="o_phone">
				<view class="text">
					联系方式
				</view>
				<view class="input">
					<input type="text" v-model="phone" placeholder="请输入手机号" placeholder-style="font-size: 24rpx;"/>
				</view>
			</view>
		</view>
		<view class="btn" @click="toSubmit">
			<view class="b">
				提交
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				mid:0,
				phone:'',
				text:'',
				imgs:[],
				http:this.$http
			}
		},
		onLoad() {
			if(uni.getStorageSync('user')){
				this.mid = uni.getStorageSync('user').id
			}
			
		},
		onShareAppMessage(e) {
			return {
				title: '',
				path: '/pages/index/index'
			}
		},
		methods: {
			toSubmit(){
				// console.log(this.text)
				if(this.text==''){
					uni.showToast({
						title:'内容不能为空',
						icon:'none'
					})
					return
				}
				if(this.phone==''){
					uni.showToast({
						title:'手机号不能为空',
						icon:'none'
					})
					return
				}
				var myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
				if (!myreg.test(this.phone)) {
					// // console.log('')
					uni.showToast({
						title:"手机号格式不正确",
						icon:'none'
					})
					return
				}
				let obj = {
					content:this.text,
					images:this.imgs.toString(),
					phone:this.phone,
					mid:this.mid
				}
				uni.showLoading({
					mask:true
				})
				this.$post('user/feedbackSubmit',obj).then(res=>{
					uni.hideLoading()
					// console.log(res)
					if(res.code==0){
						uni.showToast({
							title:'提交成功',
							icon:'success'
						})
						setTimeout(()=>{
							uni.navigateBack()
						},1000)
					}
				})
			},
			addImg(){
				this.$upload().then(res=>{
					// console.log(res)
					if(res.code==0){
						this.imgs.push(res.data.path)
					}
					
				})
			},
			changeImg(e){
				let i = e.currentTarget.dataset.i
				this.$upload().then(res=>{
					// console.log(res)
					if(res.code==0){
						// this.imgs.push(res.data.path)
						// this.imgs[i] = res.data.path
						this.$set(this.imgs,i,res.data.path)
					}
					
				})
			}
		}
	}
</script>

<style lang="less">
	image{
		width: 100%;
		height: 100%;
	}
	.opinion{
		padding: 46rpx 30rpx;
		box-sizing: border-box;
		.textarea{
			width: 690rpx;
			height: 293rpx;
			opacity: 1;
			background: #f8f8f8;
			border-radius: 40rpx;
			padding: 24rpx 19rpx;
			box-sizing: border-box;
			margin-bottom: 40rpx;
			textarea{
				width: 100%;
				height: 100%;
			}
		}
		.opinion_img{
			width: 690rpx;
			opacity: 1;
			background: #f8f8f8;
			border-radius: 20rpx;
			padding: 24rpx 19rpx;
			box-sizing: border-box;
			margin-bottom: 40rpx;
			.t_title{
				font-weight: 500;
				color: #999999;
				font-size: 24rpx;
				padding-bottom: 22rpx;
				border-bottom: 1rpx solid #efefef;
				box-sizing: border-box;
			}
			.t_list{
				display: flex;
				flex-wrap: wrap;
				.list{
					width: 119rpx;
					height: 119rpx;
					background: #efefef;
					margin-top: 34rpx;
					margin-left: 10rpx;
				}
			}
			
		}
		.opinion_p{
			width: 690rpx;
			opacity: 1;
			background: #f8f8f8;
			border-radius: 20rpx;
			padding: 24rpx 22rpx;
			box-sizing: border-box;
			margin-bottom: 40rpx;
			.o_phone{
				display: flex;
				justify-content: space-between;
				align-items: center;
				.text{
					font-weight: 500;
					color: #999999;
					font-size: 24rpx;
				}
				.input{
					width: 450rpx;
					text-align: right;
					font-size: 24rpx;
					color: #333333;
				}
			}
		}
		.box{
			width: 692rpx;
			height: 100rpx;
		}
		.btn{
			width: 692rpx;
			height: 110rpx;
			text-align: center;
			opacity: 1;
			position: fixed;
			left: 50%;
			bottom: 0rpx;
			transform: translate(-50%,0);
			padding-bottom: constant(safe-area-inset-bottom);
			padding-bottom: env(safe-area-inset-bottom);
			.b{
				background: #FF7416;
				border-radius: 43rpx;
				height: 86rpx;
				line-height: 86rpx;
				color: #fff;
				font-weight: bold;
			}
		}
	}
</style>
